package com.lc.cn.managersys.common;

import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;


public class JsonUtil {

	public static <T> String bean2Json(T obj) {
		return new Gson().toJson(obj);
	}
	
	public static <T> String list2Json(List<T> obj) {
		return new Gson().toJson(obj);
	}
	
	public static void main(String[] args) {
		SampleBean bean = new JsonUtil().new SampleBean("lg", "222");
		System.out.println(bean2Json(bean));
		
		List<SampleBean> list =new ArrayList<SampleBean>();
		SampleBean bean2 = new JsonUtil().new SampleBean("lg2", "222333");
		list.add(bean);
		list.add(bean2);
		System.out.println(list2Json(list));
		
	}
	
	class SampleBean {
		private String name;
		private String psd;
		
		public SampleBean(String name, String psd) {
			this.name = name;
			this.psd = psd;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getPsd() {
			return psd;
		}

		public void setPsd(String psd) {
			this.psd = psd;
		}
		
	}
}
